//misc javascript functions used in Adtrackz

//for modifying split test groups
function AddCampaign()
{
	//pseudo
	//add campaign to other side only if campaign is not already there
	for (var i=0; i<document.modifyform.allcampaigns.length; i++) 
	{
		if (document.modifyform.allcampaigns.options[i].selected)
		{
			var numlist = document.modifyform.campaigns.length;
			var temp = document.modifyform.allcampaigns.options[i].value;
			var flag = false; //flag to check if campaign is already there
			for (var j=0; j<document.modifyform.campaigns.length; j++) 
			{
				if (document.modifyform.campaigns.options[j].value == temp)
				{
					alert(temp+" is already in the split test group.");
					flag = true;					
				}
			}
			if (!flag)
				document.modifyform.campaigns.options[numlist] = new Option(temp,temp);
		}
//		alert(document.modifyform.campaigns.length);
	}
}

function RemoveCampaign()
{
	for (var i=0; i<document.modifyform.campaigns.length; i++) 
	{
		if (document.modifyform.campaigns.options[i].selected)
		{
			document.modifyform.campaigns.options[i] = null;
			i-=1;
		}
	}	
}

//save changes for the new split test
function AddNew()
{
	//put values of campaigns in a query string and run php script	
	//by the php script, or a series of hidden fields
	/*if (document.modifyform.campaigns.length < 2)
	{
		alert('There must be at least 2 campaigns in a given split test group. You can delete the split test group on the edit split test group menu option');
		var query_string = "?action=modify_edit&id="+id;
		document.modifyform.action = "st_edit.php"+query_string;
	}
	*/
	//alert(document.modifyform.campaigns.length);
	//var query_string = "?action=addnew&len="+document.modifyform.campaigns.length;
	//alert(query_string);



	//what this is supposed to do:
	//need a way to pass the values of the campaigns option list to the php script
	for (var i=0; i<document.modifyform.campaigns.length; i++) 
	{
		//query_string += "&option"+i+"="+document.modifyform.campaigns.options[i].value;
		f=document.createElement ("input");
		f.setAttribute ( "type", "hidden" );
		f.setAttribute ( "name", "option"+i );
		f.setAttribute ( "value", document.modifyform.campaigns.options[i].value);
		document.modifyform.appendChild(f); 
	}
	l=document.createElement ("input");
	l.setAttribute ( "type", "hidden" );
	l.setAttribute ( "name", "length" );
	l.setAttribute ( "value", document.modifyform.campaigns.length);
	document.modifyform.appendChild(l); 

	document.modifyform.submit();

	//document.modifyform.action = "st_new.php"+query_string;

}


//modify any changes
function ModifyCampaigns()
{
	//need a way to pass the values of the campaigns option list to the php script
	//so we add hidden values before the post
	for (var i=0; i<document.modifyform.campaigns.length; i++) 
	{
		f=document.createElement ("input");
		f.setAttribute ( "type", "hidden" );
		f.setAttribute ( "name", "option"+i );
		f.setAttribute ( "value", document.modifyform.campaigns.options[i].value);
		document.modifyform.appendChild(f); 
	}
	l=document.createElement ("input");
	l.setAttribute ( "type", "hidden" );
	l.setAttribute ( "name", "length" );
	l.setAttribute ( "value", document.modifyform.campaigns.length);
	document.modifyform.appendChild(l); 
}